package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;


public class BorrowOperation implements IOperation{
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的图书的名字：");
        String name = scanner.nextLine();
        int sz = bookList.getBookSize();   //获取当前书架上图书的数量
        for (int i = 0 ;i < sz ;i++) {
            if(name.equals(bookList.getBook(i).getName())) {   //通过equals方法进行名字比较
                Book book = bookList.getBook(i);
                if(book.isBorrowed() == true) {
                    System.out.println("这本书被借走了！");
                    return;
            }else {
                    System.out.println("借阅成功！");
                    book.setBorrowed(true);
                    return;
                }
        }
        System.out.println("没有这本书！");   //未找到执行
        return;
    }
    }
}
